package com.cxh.rmsq.utils.dialog

import android.content.Context
import android.graphics.Color
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
import com.blankj.utilcode.util.TimeUtils
import com.cxh.rmsq.R
import com.hjq.shape.view.ShapeTextView
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils
import kotlin.math.roundToInt


class CluePopup(context: Context, type: Int, content: String, click: onClick) :
    CenterPopupView(context) {

    interface onClick {
        fun click(s: String, s1: String)
    }

    var func: onClick
    var content: String
    var type: Int  //1 签到  2 兑换  3 邀请  4 分享  5 打卡成功  6 打卡失败  7 重置地图  8 汇款账号填资料
    var scrollView: NestedScrollView? = null

    init {
        this.func = click
        this.content = content
        this.type = type
    }

    override fun getImplLayoutId(): Int {
        return R.layout.clue_popup
    }

    override fun onCreate() {
        super.onCreate()

        var tv_title = findViewById<TextView>(R.id.tv_title)
        var tv_content_top = findViewById<TextView>(R.id.tv_content_top)
        var tv_content_child = findViewById<TextView>(R.id.tv_content_child)
        var iv_img = findViewById<ImageView>(R.id.iv_img)
        var iv_hengfu = findViewById<ImageView>(R.id.iv_hengfu)

        var tv_cancle = findViewById<TextView>(R.id.tv_cancle)
        var tv_confirm = findViewById<TextView>(R.id.tv_confirm)

        if (type == 1) {
            tv_title.text = "签到成功"
            tv_content_top.text = "签到成功"
            tv_title.isVisible = true
            iv_hengfu.isVisible = true
            tv_content_top.isVisible = true
            tv_content_child.text = "获得碎片" + content + "低级线索"
            iv_img.setImageResource(R.mipmap.icon_clue_sucess)
            iv_hengfu.setImageResource(R.mipmap.icon_clue_pop_hengfu1)
        } else if (type == 2) {
            tv_title.text = "提交成功"
            tv_content_top.text = "线索兑换申请已提交"
            tv_title.isVisible = true
            iv_hengfu.isVisible = true
            tv_content_top.isVisible = true
            tv_content_child.text = "已成功申请" + content + "低级线索"
            iv_img.setImageResource(R.mipmap.icon_clue_sucess)
            iv_hengfu.setImageResource(R.mipmap.icon_clue_pop_hengfu1)
        } else if (type == 3) {
            tv_title.text = "邀请成功"
            tv_content_top.text = "邀请成功"
            tv_title.isVisible = true
            iv_hengfu.isVisible = true
            tv_content_top.isVisible = true
            tv_content_child.text = "您已成功邀请用户注册获得" + content + "低级线索"
            iv_img.setImageResource(R.mipmap.icon_clue_sucess)
            iv_hengfu.setImageResource(R.mipmap.icon_clue_pop_hengfu1)
        } else if (type == 4) {
            tv_title.isVisible = false
            iv_hengfu.isVisible = false
            tv_content_top.isVisible = false
            tv_content_child.text = "您的发布活动申请已通过获得碎片" + content + "低级线索"
            iv_img.setImageResource(R.mipmap.icon_clue_sucess)
        } else if (type == 5) {
            tv_title.text = "打卡成功"
            tv_content_top.text = "恭喜您打卡成功"
            tv_title.isVisible = true
            iv_hengfu.isVisible = true
            tv_content_top.isVisible = true
            tv_content_child.text = "已成功收集碎片" + content
            iv_hengfu.setImageResource(R.mipmap.icon_clue_pop_hengfu1)
            iv_img.setImageResource(R.mipmap.icon_clue_sucess)
        } else if (type == 6) {
            tv_title.text = "打卡失败"
            tv_content_top.text = "您的定位未在打卡范围"
            tv_title.isVisible = true
            iv_hengfu.isVisible = true
            tv_content_top.isVisible = true
            tv_content_child.text = "请到活动地点10米内重新打卡"
            iv_img.setImageResource(R.mipmap.icon_clue_failed)
            iv_hengfu.setImageResource(R.mipmap.icon_clue_pop_hengfu2)
        }else if (type == 7) {
            tv_content_top.text = "确定放弃地图收集吗？"
            tv_title.isVisible = false
            iv_hengfu.isVisible = false
            tv_content_top.isVisible = true
            tv_cancle.isVisible = true
            tv_content_child.text = "放弃后已支付金额不返还，收集进 度清零"
            iv_img.setImageResource(R.mipmap.icon_clue_fragments)
        } else if (type == 8) {
            tv_content_top.isVisible = false
            tv_title.isVisible = false
            iv_hengfu.isVisible = false
            tv_cancle.isVisible = false

            tv_confirm.text = "去填写"
            tv_content_child.text = "您的"+content+"1已收集成功检测到您未填写收款账户请前往编辑资料处填写"
            iv_img.setImageResource(R.mipmap.icon_clue_sucess)
        }

        tv_title.setShadowLayer(4F, 2F, 2F, Color.parseColor("#842F00"))
        tv_content_top.setShadowLayer(4F, 2F, 2F, Color.parseColor("#842F00"))

        tv_cancle.setOnClickListener {
            dismiss()
        }
        tv_confirm.setOnClickListener {
            func.click(
                "",
                ""
            )
            dismiss()
        }
    }

    // 最大高度为Window的0.85
    override fun getMaxHeight(): Int {
        return ((XPopupUtils.getAppHeight(context) * .85f).roundToInt())
    }

}